package com.woniuxy.woniuhis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woniuxy.woniuhis.entity.SurgeryEmpArr;
import com.woniuxy.woniuhis.entity.SurgeryRole;
import com.woniuxy.woniuhis.exception.SurgeryEmpArrServiceException;
import com.woniuxy.woniuhis.mapper.EmpMapper;
import com.woniuxy.woniuhis.mapper.SurgeryEmpArrMapper;
import com.woniuxy.woniuhis.mapper.SurgeryRoleMapper;
import com.woniuxy.woniuhis.service.SurgeryEmpArrService;

/**
 * 
 *	手术人员安排
 */
@Service
public class SurgeryEmpArrServiceImpl implements SurgeryEmpArrService{
	
	@Autowired
	SurgeryEmpArrMapper surgeryEmpArrMapper;
	
	@Autowired
	EmpMapper empMapper;
	
	@Autowired
	SurgeryRoleMapper surgeryRoleMapper;
	/**
	 * 	添加手术人员安排
	 */
	@Override
	@Transactional
	public void addSurgeryEmpArr(List<SurgeryEmpArr> surgeryEmpArrs) {
		try {
			for(SurgeryEmpArr sur:surgeryEmpArrs) {
				surgeryEmpArrMapper.insertSurgeryEmpArr(sur);
			}
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	
	/**
	 * 	添加手术人员安排
	 */
	@Override
	public void addSurgeryEmpArr(SurgeryEmpArr surgeryEmpArr) {
		try {
			surgeryEmpArrMapper.insertSurgeryEmpArr(surgeryEmpArr);
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	/**
	 * 	更新手术人员安排
	 */
	@Override
	public void modifySurgeryEmpArr(SurgeryEmpArr surgeryEmpArr) {
		try {
			surgeryEmpArrMapper.updateSurgeryEmpArr(surgeryEmpArr);
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	/**
	 * 	查询指定id的手术人员安排
	 */
	@Override
	public SurgeryEmpArr findSurgeryEmpArrById(String id) {
		try {
			return surgeryEmpArrMapper.selectSurgeryEmpArrById(id);
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	/**
	 * 	查询指定手术的手术人员安排
	 */
	@Override
	public List<SurgeryEmpArr> findSurgeryEmpArrBySurgeryId(String surgeryExeId) {
		try {
			List<SurgeryEmpArr> surgeryEmpArrs = surgeryEmpArrMapper.selectSurgeryEmpArrBySurgeryId(surgeryExeId);
			for(SurgeryEmpArr arr:surgeryEmpArrs) {
				// 查医生护士信息
				arr.setEmp(empMapper.selectEmpById(arr.getEmpId()));
				// 查角色名
				arr.setSurgeryRole(surgeryRoleMapper.selectSurgeryRoleById(arr.getSurgeryRoleId()));
			}
			return surgeryEmpArrs;
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	/**
	 * 	查询所有手术的手术人员安排
	 */
	@Override
	public List<SurgeryEmpArr> findSurgeryEmpArrs() {
		try {
			return surgeryEmpArrMapper.selectSurgeryEmpArrs();
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}
	/**
	 * 	删除指定手术人员安排
	 */
	@Override
	public void delSurgerySurgeryEmpArrById(String id) {
		try {
			surgeryEmpArrMapper.deleteSurgerySurgeryEmpArrById(id);
		} catch (Exception e) {
			throw new SurgeryEmpArrServiceException(e);
		}
	}

}
